import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { SpectrumService } from './spectrum.service';
import { CreateSpectrumDto, BaseSpectrumDto, UpdateSpectrumDto, QuerySpectrumDto, ListSpectrumDto, QueryInfoSpectrumDto } from './dto/spectrum.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('学生心理光谱表，存储孩子的心理评估数据和报告')
@Controller('system/spectrum')
export class SpectrumController {
  constructor(private readonly spectrumService: SpectrumService) {}

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-创建' })
  @ApiDataResponse(BaseSpectrumDto)
  @RequirePermission('system:spectrum:add')
  @Post()
  create(@Body() body: CreateSpectrumDto) {
    return this.spectrumService.create(body);
  }

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-列表' })
  @ApiDataResponse(ListSpectrumDto, true, true)
  // @RequirePermission('system:spectrum:list')
  @Get('list')
  findAll(@Query() query: QuerySpectrumDto) {
    return this.spectrumService.findAll(query);
  }

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-列表' })
  @ApiDataResponse(ListSpectrumDto, true, true)
  // @RequirePermission('system:spectrum:list')
  @Get('info')
  findInfo(@Query() query: QueryInfoSpectrumDto) {
    // 现在query对象将包含childId和pageNum参数
    return this.spectrumService.findInfo(query);
  }

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-详情' })
  @ApiDataResponse(BaseSpectrumDto)
  // @RequirePermission('system:spectrum:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.spectrumService.findOne(id);
  }

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-修改' })
  @ApiDataResponse()
  @RequirePermission('system:spectrum:edit')
  @Put()
  update(@Body() body: UpdateSpectrumDto) {
    return this.spectrumService.update(body);
  }

  @ApiOperation({ summary: '学生心理光谱表，存储孩子的心理评估数据和报告-删除' })
  @ApiDataResponse()
  @RequirePermission('system:spectrum:remove')
  @Delete(':id')
  remove(@Param('id') id: string) {
    const ids = id.split(',').map((id) => +id);
    return this.spectrumService.remove(ids);
  }
}
